try {
	Type.registerNamespace('NCMMHttpUtil');
	//定义全局变量
	NCMMHttpUtil.IP = "172.16.4.242:9082";
	NCMMHttpUtil.EXSYSTEMCODE = "BarCode99";
	NCMMHttpUtil.DEVICECODE = "PDA";
	NCMMHttpUtil.DEVICEUNIQUEID = "PDA"
	NCMMHttpUtil.USER = "zdd";
	NCMMHttpUtil.PASSWORD = "123456a";
	NCMMHttpUtil.LOGIN = "mmexbdlogin";
	NCMMHttpUtil.TEST = "mmexbdtest";
	NCMMHttpUtil.BDDOC = "mmquerybddoc";
	NCMMHttpUtil.BILL = "mmqueryncbills";
	NCMMHttpUtil.BILLUPDATE = "mmbillbusiness";
	NCMMHttpUtil.ICMODULECODE = "IC";

	//获取NC端请求URL
	NCMMHttpUtil.getQuestURL = function(svrname) {
		var currentIP = $cache.read("ServerIP");
		if(!(currentIP == null || currentIP == "")) {
			NCMMHttpUtil.IP = currentIP;
		}
		return "http://" + NCMMHttpUtil.IP + "/service/" + svrname;
	};
	//获取NC端请求URL
	NCMMHttpUtil.getDeviceUniqueID = function() {
		var deviceInfo = $device.getDeviceInfo();
		var jsondevice = $stringToJSON(deviceInfo);
		var deviceuniqueid = jsondevice.deviceid;
		if(!(deviceuniqueid == null || deviceuniqueid == "")) {
			NCMMHttpUtil.DEVICEUNIQUEID = deviceuniqueid;
		}
		return NCMMHttpUtil.DEVICEUNIQUEID;
	};

	//组装NC端请求参数
	NCMMHttpUtil.getHTTPRequestParam = function(docType, aggvo, condition) {
		initializeRequestParam();
		var nccontext = {
			"user": NCMMHttpUtil.USER,
			"password": NCMMHttpUtil.PASSWORD,
			"exsystemcode": NCMMHttpUtil.EXSYSTEMCODE,
			"modulecode": NCMMHttpUtil.ICMODULECODE,
			"devicecode": NCMMHttpUtil.DEVICECODE,
			"deviceuniqueid": NCMMHttpUtil.getDeviceUniqueID(),
			"doctype": docType,
			"returntype": aggvo
		};

		var totalrows = "-1";
		var startRowNumber = "1";
		if(condition && condition["startRowNumber"]){
			startRowNumber = (condition["startRowNumber"]).toString();
		}
		var endRowNumber = "5000";
		if(condition && condition["endRowNumber"]){
			endRowNumber = (condition["endRowNumber"]).toString();
		}
		var queryinfos = {
			"totalRows": totalrows,
			"startRowNumber": startRowNumber,
			"endRowNumber": endRowNumber
		};
		if(condition != null) {
			for(var key in condition) {
				queryinfos[key] = condition[key];
			}
			//			$alert("conditionqueryinfos="+ $jsonToString(queryinfos));
		}
		var jsonparam = {
			"nccontext": nccontext,
			"queryinfos": queryinfos
		};

		return jsonparam;
	};

	//组装NC端提交请求参数
	NCMMHttpUtil.getHTTPSubmitParam = function(ncbillcode, billinfos) {
		initializeRequestParam();
		var nccontext = {
			"user": NCMMHttpUtil.USER,
			"password": NCMMHttpUtil.PASSWORD,
			"exsystemcode": NCMMHttpUtil.EXSYSTEMCODE,
			"modulecode": NCMMHttpUtil.ICMODULECODE,
			"devicecode": NCMMHttpUtil.DEVICECODE,
			"deviceuniqueid": NCMMHttpUtil.getDeviceUniqueID(),
			"doctype": ncbillcode
		};

		var jsonparam = {
			"nccontext": nccontext,
			"billinfos": billinfos
		};

		return jsonparam;
	};

	//发送HTTP请求到NC
	NCMMHttpUtil.sendHTTPRequest = function(httpURL, httpparam, callback) {
		$.ajax({
			type: 'POST',
			beforeSend: function(req) {
				req.setRequestHeader("accept", "application/json");
			},
			url: httpURL,
			"data": JSON.stringify(httpparam),
			timeout: 120000,
			success: function(data, status) {
				//				$alert("original nc data=" + data);
				if(data == null || data == "") {
					data = {};
					data["error"] = "没有获取到NC数据。";
					if(callback != null && typeof(callback) == 'function') {
						callback(data, 2); //2： 请求成功，返回值为空
					};
				} else {
					if($isPlainObject(data) == false) {
						data = $stringToJSON(data);
					}
					if(callback != null && typeof(callback) == 'function') {
						callback(data, 1); //1：请求成功, 返回有效的response数据
					};
				}
			},
			error: function(data) {
				if(callback != null && typeof(callback) == 'function') {
					callback(data, 0); //0：请求失败，返回服务端提示的错误信息
				};
			}
		});
	};

	// $service.post请求
	//from wjw
	NCMMHttpUtil.servicePost = function(url, data, callback, error, userTag) {
		userTag = userTag || '';
		$app.ajax({
			"url": url, // 请求url地址
			'method': 'post',
			'type': 'json',
			'tag': userTag,
			"data": data, // 请求参数
			"callback": callback, // 请求成功后回调js方法
			"error": error, // 异常回调
			'header': {
				'Content-Type': 'application/json'
			},
			"timeout": 15000
		})
	};

	//本地当前时间，格式 -- YYYY年MM月DD日 hh:mm
	NCMMHttpUtil.getCurrentLocalTime = function() {
		var d = new Date();
		var strDate = d.getFullYear() + "年" +
			fillToSpecialDigit(2, "0", (d.getMonth() + 1).toString()) + "月" +
			fillToSpecialDigit(2, "0", d.getDate().toString()) + "日 " +
			fillToSpecialDigit(2, "0", d.getHours().toString()) + ":" +
			fillToSpecialDigit(2, "0", d.getMinutes().toString());

		return strDate;
	};

	function fillToSpecialDigit(len, chr, str) {
		var diff = len - str.length;
		if(diff <= 0)
			return str;

		var fillstr = ""
		for(var i = 0; i < diff; i++) {
			fillstr = fillstr + chr;
		}
		str = fillstr + str;
		return str;
	}

	function initializeRequestParam() {
		var currentuser = $cache.read("username");
		if(!(currentuser == null || currentuser == "")) {
			NCMMHttpUtil.USER = currentuser;
		}
		var currentpwd = $cache.read("password");
		if(!(currentpwd == null || currentpwd == "")) {
			NCMMHttpUtil.PASSWORD = currentpwd;
		}
	};

} catch(e) {
	$e(e);
}